package taiyuaneltyl.com.my_mvp.model;

import android.util.Log;

import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import okhttp3.Call;

import taiyuaneltyl.com.my_mvp.presenter.LoginOnListener;

/**
 * Created by Administrator on 2018/3/31.
 * <p>
 * 网络请求的实现
 */

public class LoginNetIml implements LoginNet {

    @Override
    public void Login(String name, String pwd, String rid, final LoginOnListener loginOnListener) {

  /**
 * 请求成功在onResponse方法判断response不等于null 调用loginOnListener.onpSuccess(response);
 * 等于null 调用 loginOnListener.onError();
 * 请求失败onError 调用 loginOnListener.onError();
 */
        OkHttpUtils
                .get()
                .url("http://api.eltyl.com/index.php/Home/App/dologin")
                .addParams("mobile", name)
                .addParams("password", pwd)
                .addParams("regid", rid)
                .build()
                .execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                           loginOnListener.onError();
                    }

                    @Override
                    public void onResponse(String response, int id) {
                        Log.v("111111",response);
                        if (response != null) {
                            loginOnListener.onpSuccess(response);
                        } else {
                            loginOnListener.onError();
                        }

                    }
                });
    }
}
